#include "../include/DirectoryScanner.h"
#include "../include/log4cppuse.h"

#include <dirent.h>
#include <unistd.h>

using namespace std;

 DirectoryScanner& DirectoryScanner::getDirectoryScanner()
{
        static DirectoryScanner directoryscanner;
        return directoryscanner;
}
std::vector<std::string> DirectoryScanner::scan(const std::string& dir)
{
    DIR* dp=opendir(dir.c_str());
    if(dp==nullptr)
    {
        std::string log=dir+":无法打开目录";
        LOG_ERROR(log.c_str());
        return {};
    }

    struct dirent* entry;
    std::vector<std::string> files;
    while((entry=readdir(dp))!=nullptr)
    {
        std::string filename=entry->d_name;
        if(filename==string(".") || filename==string(".."))
        {
            continue;
        }
        files.push_back(dir+"/"+filename);
    }
    
    closedir(dp);
    return files;
}


